//
//  DetailProductClassifyController.m
//  nmrsc
//
//  Created by xumckay on 16/1/16.
//  Copyright © 2016年 bric. All rights reserved.
//

//-----商品详情的二级页面----//
#import "DetailProductClassifyController.h"
@interface DetailProductClassifyController ()

@property (strong,nonatomic)UITableView *ProductListTableView;//视图左侧产品列表的table
@property (strong,nonatomic)UITableView *DetailTableView;//视图右侧具体的table
@property (strong,nonatomic)UIScrollView *BGScrollerView;
@property (strong,nonatomic)NSArray *ListArray;
@property (strong,nonatomic)NSArray *ProductArray;
@property (assign,nonatomic)NSInteger saveOffset; //记录当前偏移的量

@end

@implementation DetailProductClassifyController


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    NAVBAR(@"商品详情");
    
    UIButton *backBtn=[[UIButton alloc]initWithFrame:CGRectMake(0,0,8.5,15)];
    [backBtn setImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
    [backBtn addTarget:self action:@selector(backClicked) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem=[[UIBarButtonItem alloc]initWithCustomView:backBtn];
    
    _BGScrollerView=[[UIScrollView alloc]initWithFrame:CGRectMake(0,64,kDeviceWidth,kDeviceHeight-64)];
    _BGScrollerView.contentSize=CGSizeMake(kDeviceWidth/3+kDeviceWidth,kDeviceHeight-64);
    _BGScrollerView.bounces=NO;
    _BGScrollerView.alwaysBounceHorizontal = YES;
    _BGScrollerView.showsHorizontalScrollIndicator = NO;
    _BGScrollerView.delegate=self;

    [self.view addSubview:_BGScrollerView];
    
    _ListArray=@[@"蔬菜",@"水果",@"肉类产品"];
    _ProductArray=@[@"啊啊啊",@"一样一样"];
    _saveOffset=0;
    [self addTableView];
}

-(void)addTableView
{
    _ProductListTableView=[[UITableView alloc]initWithFrame:CGRectMake(0,0,kDeviceWidth/3,_BGScrollerView.height)];
    _ProductListTableView.tag=120;
    _ProductListTableView.delegate=self;
    _ProductListTableView.dataSource=self;
    [_BGScrollerView addSubview:_ProductListTableView];
    
    _DetailTableView=[[UITableView alloc]initWithFrame:CGRectMake(kDeviceWidth/3,0,kDeviceWidth,_BGScrollerView.height)];
    _DetailTableView.tag=121;
    _DetailTableView.delegate=self;
    _DetailTableView.dataSource=self;
    [_BGScrollerView addSubview:_DetailTableView];

}

#pragma mark   ---UITableViewDelegate

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (tableView.tag==120) {
        return _ListArray.count;
    }
    else if(tableView.tag==121)
    {
        return _ProductArray.count;
    }
    return 0;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView.tag==120) {
       
        static NSString *identifier=@"cell1";
        UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:identifier];
        if (!cell) {
            cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
        }
        cell.textLabel.text=[_ListArray objectAtIndex:indexPath.row];
        return cell;
        
    }
    else if(tableView.tag==121)
    {
        static NSString *identifier2=@"cell2";
        UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:identifier2];
        if (!cell) {
            cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier2];
        }
        cell.textLabel.text=[_ProductArray objectAtIndex:indexPath.row];
        
        return cell;
  }
    return nil;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView.tag==120) {
//        return 1;
    }
    else if(tableView.tag==121)
    {
//        return 2;
    }

}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView.tag==120) {
        return 60;
    }
    else if(tableView.tag==121)
    {
        return 120;
    }
    return 0;
}

-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    
    CGFloat x=scrollView.contentOffset.x;
    if (x<kDeviceWidth/6&&x>0) {
        [_BGScrollerView setContentOffset:CGPointMake(0,0)];
        
    }
    else if(x>=kDeviceWidth)
    {
        [_BGScrollerView setContentOffset:CGPointMake(kDeviceWidth/3,0)];
        
    }
    else if(x==0)
    {
        return;
    }
}



-(void)backClicked
{
    [self.navigationController popViewControllerAnimated:YES];
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
